const { expressjwt } = require('express-jwt');
const { jwtConfig } = require('../config');

function route(app) {
  // 后台 API
  app.use('/b', expressjwt({
    secret: jwtConfig.secretBack,
    algorithms: ['HS256'] // express-jwt 6.x 版本后需要设置算法，否则会报 algorithms should be set 的错误
  }).unless({
    path: ['/b/users/login']  //除了这个地址，其他的URL都需要验证
  }));

  app.use('/b/users', require('./back/users'));
  app.use('/b/activity', require('./back/activity'));

  // 前台 API
  app.use('/f', expressjwt({
    secret: jwtConfig.secretFront,
    algorithms: ['HS256']
  }).unless({
    path: [
      '/f/users/login',
      '/f/users/register',
      '/f/users/check',
      '/f/activity/list',
      '/f/activity/total',
      '/f/activity/get',
      '/f/activity/category'
    ]
  }));

  app.use('/f/users', require('./front/users'));
  app.use('/f/activity', require('./front/activity'));
}
module.exports = route;
